<template>
	<view class="container">
		<tui-tabs :tabs="tabs" :isFixed="scrollTop>=0" :currentTab="currentTab" @change="change" itemWidth="20%">
		</tui-tabs>

		<tui-show-empty v-if="orderList.length<=0" text="暂无订单"></tui-show-empty>
		<view :class="{'tui-order-list':scrollTop>=0}" v-else>
			<view class="tui-order-item" v-for="(order,orderIndex) in orderList" :key="orderIndex">
				<order-column v-if="order.orderType != 6 && order.orderType != 7 && order.orderType != 8"
					:value="order"></order-column>
				<order-hotel-column v-else-if="order.orderType == 8" :value="order"></order-hotel-column>
				<order-food-column v-else-if="order.orderType == 7" :value="order"></order-food-column>
				<order-scenic-column v-else :value="order"></order-scenic-column>
			</view>
			<tui-nomore backgroundColor="#fafafa"></tui-nomore>
		</view>
	</view>
</template>

<script>
	const util = require("@/utils/util.js")
	import OrderScenicColumn from '@/pagesA/components/order-scenic-column.vue'
	import OrderHotelColumn from '@/pagesA/components/order-hotel-column.vue'
	import OrderFoodColumn from '@/pagesA/components/order-food-column.vue'
	import OrderColumn from './components/order-column.vue'
	export default {
		components: {
			OrderScenicColumn,
			OrderHotelColumn,
			OrderFoodColumn,
			OrderColumn
		},
		data() {
			return {
				scrollTop: 0,
				orderStatus: -2,
				evaluate_status: '',
				orderTypes: '',
				orderList: [],
				current: 1,
				limit: 10,
				tabs: [{
					name: "全部"
				}, {
					name: "待付款"
				}, {
					name: "待发货"
				}, {
					name: "待收货"
				}, {
					name: "待评价"
				}, {
					name: "待使用"
				}],
				currentTab: 0,
				sweixin: null
			}
		},
		onLoad: function(options) {
			let that = this;
			// 页面初始化 options为页面跳转所带来的参数
			if (options.currentTab) {
				that.currentTab = parseInt(options.currentTab)
			}

			// #ifdef APP-PLUS
			plus.share.getServices(function(s) {
				var shares = {};
				for (var i = 0; i < s.length; i++) {
					var t = s[i];
					shares[t.id] = t;
				}

				that.sweixin = shares['weixin']
			}, function(e) {
				console.log("获取分享服务列表失败：" + e.message);
			});
			//#endif
		},
		methods: {
			change(e) {
				this.currentTab = e.index
				this.orderList = []
				this.current = 1
				this.switchOrderType(e.index);
			},
			getOrderList() {
				let that = this;
				util.request('order/list', {
					orderStatus: that.orderStatus,
					orderTypes: that.orderTypes,
					current: that.current,
					limit: that.limit
				}).then(function(res) {
					if (res.code === 0) {
						that.orderList = res.data.records;
					}
				});
			},
			switchOrderType(currentTab) {
				let that = this;
				that.orderTypes = '';
				if (currentTab == 0) {
					that.orderStatus = -2;
				} else if (currentTab == 1) {
					that.orderStatus = 0;
				} else if (currentTab == 2) {
					that.orderStatus = 201;
					that.orderTypes = '1,2,3,4,5';
				} else if (currentTab == 3) {
					that.orderStatus = 300;
				} else if (currentTab == 4) {
					that.orderStatus = 301;
				} else if (currentTab == 5) {
					that.orderStatus = 201;
					that.orderTypes = '6,7,8';
				}
				that.getOrderList();
			}
		},
		onShow: function() {
			// 页面显示
			let that = this;
			that.switchOrderType(that.currentTab);
		},
		// 下拉刷新
		onPullDownRefresh: function() {
			// 显示顶部刷新图标
			uni.showNavigationBarLoading();
			this.getOrderList();
			// 隐藏导航栏加载框
			uni.hideNavigationBarLoading();
			// 停止下拉动作
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			var that = this;
			that.limit = that.limit + 10;
			that.getOrderList();
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		}
	}
</script>

<style>
	.tui-order-list {
		margin-top: 80rpx;
	}

	.tui-order-item {
		margin-top: 20rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}
</style>
